package org.smartboot.flow.testcase.extension;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smartboot.flow.core.EngineContext;
import org.smartboot.flow.core.ExecutionListener;
import org.smartboot.flow.core.ExtensionAttribute;
import org.smartboot.flow.core.component.Component;
import org.smartboot.flow.core.util.AuxiliaryUtils;

import java.util.List;


public class EchoAllAttributesExecutionListener implements ExecutionListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(EchoAllAttributesExecutionListener.class);


    @Override
    public <T, S> void beforeExecute(EngineContext<T, S> ctx, Object object) {

        if (!(object instanceof Component)) {
            return;
        }

        Component comp = (Component) object;

        List<ExtensionAttribute> extensionAttributes = comp.get();
        if (extensionAttributes.size() == 0) {
            return;
        }

        StringBuilder sb = new StringBuilder();

        extensionAttributes.forEach(p -> {
            p.getValues().forEach((k,v) -> sb.append(k).append(": ").append(v).append("\n"));
        });


        LOGGER.info("component: {} extensions: \n{}", comp.describe(), sb);
    }
}
